﻿var checkTime = null;
var selpoint=0;
var dt1=0;
var dt2=0;
var nlines;
var center;
var lat=0.0;
var lon=0.0;
var lat1,lon1;
var mapsel;
var map;
var map1;
var map2;
var rg;
var with_car_routing=0;load_directions=0;
var directions,geocoder;
var userPoints = [];
var userLine;
var initmap=0;
var initmap1=0;
var maplstnr=0;
var sregion=0;
var geocoder;
var center_zoom=12;
var c_z;
var center_x=23.745;
var center_y=37.989;
var center_x=23.76;
var center_y=37.89;
var currentcenter=r_g(center_y,center_x);
var currentzoom=11;
var faddress1,faddress2;
var markers=[];
var mrkcolor=new Array("red","green","blue","orange","yellow","black","purple","white");
var pi=3.141592654/180;

var r1=0;
var r2=0;
var gps=0;
var reqDate;
var checkUpdate;
var copied;
var active=1;
var changeactive=0;
var period;
var email;
var rcvd;
var vsend;

function r_l(i){return(parseFloat(document.forms[0].elements[i].value));}
function s_l(i,v){document.forms[0].elements[i].value=v;}
function r_g(la,ln){return(new google.maps.LatLng(la,ln));}
function r_i(s){return(document.getElementById(s).selectedIndex);}
function s_i(s,v){document.getElementById(s).selectedIndex=v;}
function s_v(s,v){document.getElementById(s).style.visibility=v;}
function r_id(s){return(document.getElementById(s).value);}
function s_id(s,v){document.getElementById(s).value=v;}
function r_c(s){return(document.getElementById(s).checked);}
function s_c(s){document.getElementById(s).checked=1;}
function r_o(s,i){return(document.getElementById(s).options[i].selected);}
function getLocation() {
  navigator.geolocation.getCurrentPosition(Location, Error, {enableHighAccuracy:true,maximumAge:10000});
}
function Error(error) {};
function Location(position) {
    dt1=1;
    try{
	tpos=r_g(position.coords.latitude,position.coords.longitude);
	map.clearOverlays();
        placeMarker(tpos);
    }catch(e){}
}

function firstin(){
if(parent.process=="go"){
ss=parent.getpswd;
   s = ""
   for(i=1;i< ss.length;i++){
       if(ss.substr(i,1)=="="){
            if(ss.charCodeAt( i + 1)<58) {s = s + ss[i+1];i++}else{
            a = ss.charCodeAt( i + 1);if( a >= 65)  a = a - 7;
            a = a - 48;
            b = ss.charCodeAt( i + 2);if( b>= 65)  b = b - 7;
            b = b - 48;
            s = s + String.fromCharCode(a * 16 + b+720); i = i + 2;}
       }else{
            s = s + ss[i];
       }
    }
var ss=s.split("|");
s_id("firstname",ss[0]);
s_id("name",ss[1]);
s_id("phone",ss[2]);
email=ss[3];
s_id("username",parent.username);
s_v("password",'hidden');
sendrequest_4();
s_v("home",'visible');
}else{
s_v("password",'visible');
s_v("home",'hidden');
}
s_v("check",'hidden');
s_v("success",'hidden');
s_v("trim",'hidden');
s_v("move",'hidden');
s_v("map",'hidden');
s_v("msg",'hidden');
}
function home(){
s_v("home",'visible');
s_v("msg",'hidden');
s_v("move",'hidden');
s_v("password",'hidden');
s_v("check",'hidden');
s_v("success",'hidden');
s_v("trim",'hidden');
s_v("map",'hidden');
}
function move(){
s_v("msg",'hidden');
s_v("move",'visible');
s_v("password",'hidden');
s_v("check",'hidden');
s_v("success",'hidden');
s_v("trim",'hidden');
s_v("map",'visible');
initialize(center_x,center_y,center_zoom,0);
}
function check(){
s_v("password",'hidden');
s_v("check",'visible');
time=new Date();
day=time.getDate();
month=time.getMonth()+1;
year=time.getYear()+1900;
tm1=time.getHours();
tm2=time.getMinutes();
reqDate=day+"/"+month+"/"+year
for(i=0;i<31;i++) if(document.getElementById("day").item(i).value==day) {document.getElementById("day").selectedIndex=i;break;}
for(i=0;i<12;i++) if(document.getElementById("month").item(i).value==month) {document.getElementById("month").selectedIndex=i;break;}
for(i=0;i<5;i++) if(document.getElementById("year").item(i).value==year) {document.getElementById("year").selectedIndex=i;break;}
for(i=0;i<24;i++) if(document.getElementById("hour").item(i).value==tm1) {document.getElementById("hour").selectedIndex=i;break;}
for(i=0;i<60;i++) if(document.getElementById("minutes").item(i).value==tm2) {document.getElementById("minutes").selectedIndex=i;break;}
}
function check1(){
document.getElementById("subm").disabled="disabled";
clearTimeout(checkTime);
checkTime=setTimeout('submenable()',5000);
}
function submenable(){s_v("success",'hidden');document.getElementById("subm").disabled="";firstin();}
function trim(){
s_v("home",'hidden');
s_v("msg",'hidden');
s_v("move",'hidden');
s_v("map",'hidden');
s_v("check",'hidden');
s_v("success",'hidden');
s_v("trim",'visible');
}

function initialize(c_x,c_y,c_z,clr) {
 if (map==null) {
   var mapOptions = {
       center: new google.maps.LatLng(37.9837, 23.7291),
         mapTypeControl: true,
         mapTypeControlOptions: {
          style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
        },
	disableDefaultUI: true,
        zoomControl: true,
        zoomControlOptions: {
         style: google.maps.ZoomControlStyle.LARGE
        },
        zoom: 11,
       mapTypeId: google.maps.MapTypeId.ROADMAP
   };
   map = new google.maps.Map(document.getElementById('map'),mapOptions);
   geocoder = new google.maps.Geocoder();
   TaxiImage = new google.maps.MarkerImage('./i/taxi.png',
   new google.maps.Size(40, 40),
   new google.maps.Point(0,0),
   new google.maps.Point(20, 20));
   var input = document.getElementById('addr1');
   var autocomplete = new google.maps.places.Autocomplete(input);
   autocomplete.bindTo('bounds', map);
   infowindow = new google.maps.InfoWindow();

   google.maps.event.addListener(autocomplete, 'place_changed', function() {
     infowindow.close();
     dt1=1;
     map.clearOverlays();
     place = autocomplete.getPlace();
     if (place.geometry.viewport) {
       map.fitBounds(place.geometry.viewport);
     } else {
       map.setCenter(place.geometry.location);
       map.setZoom(15);
     }

     var address = '';
     if (place.address_components) {
        address = [
        (place.address_components[0] && place.address_components[0].short_name || ''),
        (place.address_components[1] && place.address_components[1].short_name || ''),
        (place.address_components[2] && place.address_components[2].short_name || '')
        ].join(' ');
      }
      placeMarker_1(place.geometry.location,address);
      s_v("nodir",'hidden');
    });
    google.maps.event.addDomListener(window, 'load', initialize);
    google.maps.Map.prototype.clearOverlays = function() {
     if (markers) {
      for (var i = 0; i < markers.length; i++ ) {
       markers[i].setMap(null);
      }markers.length=0;
     }
    }
    google.maps.event.addListener(map, 'click', function(event) {
      s_id("addr1","");
      s_v("nodir",'hidden');
      map.clearOverlays();
      placeMarker(event.latLng);
    });
}
}
function placeMarker(location) {
codeLatLng(location);
map.setCenter(location);
x1coord=location.lng();
y1coord=location.lat();
s_id("point1","(" + parseInt(x1coord*1e+06)/1e+06 + "," + parseInt(y1coord*1e+06)/1e+06 + ")");
map.setZoom(15);
}
function placeMarker_1(location,address) {
var image="../i/start.png";
createMarker(location,address,0,image);
x1coord=location.lng();
y1coord=location.lat();
s_id("point1","(" + parseInt(x1coord*1e+06)/1e+06 + "," + parseInt(y1coord*1e+06)/1e+06 + ")");
map.setCenter(location);
map.setZoom(17);
}
function codeLatLng(latlng) {
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
a=results[0].formatted_address;
s_id("addr1",results[0].formatted_address);
var image="../i/start.png";
createMarker(latlng,results[0].formatted_address,0,image);}
}else {
s_v("nodir",'visible')
}
});
}
function createMarker(latlng,content, myNum, myIcon) {
    var contentString = content;
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        icon: myIcon,
        zIndex: Math.round(latlng.lat() * -100000) << 5,
        title: content
    });

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(contentString);
        infowindow.open(map, marker);
    });

    markers.push(marker); //push local var marker into global array
}
function ggcode(){
if(dt1==0){
geocoder.geocode({'address' : r_id("addr1")}, function(results, status){
map.clearOverlays();
var marker = new google.maps.Marker({
map: map
});
if(results[0]!=null){
placeMarker_1(results[0].geometry.location,r_id("addr1"));
map.setCenter(results[0].geometry.location);
map.setZoom(17);
dt1=1;
s_v("nodir",'hidden');
}else s_v("nodir","visible");
});
}
}
function sendrequest_2(){
 document.getElementById("inp").disabled=true;
 username=r_id("username");
 password=r_id("code");
 vsend=username+"|"+password+"2"
 m="";for(i=0;i<=vsend.length;i++) if(vsend.charAt(i)==" ") m=m+"_"; else m=m+vsend.charAt(i);
 vsend=m;
 ajaxFunction();
}

function sendrequest_3(){
username = r_id("username");
time=new Date();
tm1=(time.getHours()<10)?"0"+time.getHours():time.getHours();
tm2=(time.getMinutes()<10)?"0"+time.getMinutes():time.getMinutes();
tm3=(time.getSeconds()<10)?"0"+time.getSeconds():time.getSeconds();
reqTime = tm1+":"+tm2+":"+tm3;
r=reqDate;reqDate=r+" "+reqTime;
firstname=r_id("firstname");
name=r_id("name");
phone=r_id("phone");
a=document.getElementById("day").selectedIndex+1;
b=document.getElementById("month").selectedIndex+1;
c=document.getElementById("year").selectedIndex+2012;
AppDate=a+"/"+b+"/"+ c;
AppTime=document.getElementById("hour").selectedIndex+":"+document.getElementById("minutes").selectedIndex;
AppDate=AppDate+" "+AppTime;
s=r_id("addr1");s=s.substr(0,25);s_id("addr1","");
from_street=s;
from_region="_";
from_point=r_id("point1");
to_street=s;
to_region="_";
to_point=r_id("point1");
passengers=1;
luggages=0;
carpooling=0;
period="0000000";
disable=(active)?"":"-";
plus="3";if(checkUpdate==1){
plus="|"+copied+"6";}
s=username+"|"+disable+email+"|"+reqDate+"|"+firstname+"|"+name+"|"+phone+"|"+AppDate+"|"+from_street+"|"+from_region+"|"+from_point+"|"+to_street+"|"+to_region+"|"+to_point+"|"+passengers+"|"+luggages+"|"+carpooling+"|"+period+"|"+active+plus;
ns=s.replace(/\/\ /g,"/");
s=ns.replace(/\:\ /g,":");
vsend=s;
m="";for(i=0;i<=vsend.length;i++) if(vsend.charAt(i)==" ") m=m+"_"; else m=m+vsend.charAt(i);
vsend=m;
ajaxFunction();
}
function sendrequest_4(){
vsend=r_id("username")+"4"
ajaxFunction();
}
function sendrequest_5(){
if(document.getElementById("show").selectedIndex==-1) return;
s=document.getElementById("show").options[document.getElementById("show").selectedIndex].text;
l=s.search(" <");
a=s.substr(0,l);
copied=s.substr(0,l);
s=r_id("username")+"|"+s.substr(0,l)+"5";
ns=s.replace(/\/\ /g,"/");
s=ns.replace(/\:\ /g,":");
vsend=s;
m="";for(i=0;i<=vsend.length;i++) if(vsend.charAt(i)==" ") m=m+"_"; else m=m+vsend.charAt(i);
vsend=m;
ajaxFunction();
}
function sendrequest_7(){
if(document.getElementById("show").selectedIndex==-1) return;
s=document.getElementById("show").options[document.getElementById("show").selectedIndex].text;
l=s.search(" <");
a=s.substr(0,l);
s=r_id("username")+"|"+s.substr(0,l)+"7";
ns=s.replace(/\/\ /g,"/");
vsend=ns;
m="";for(i=0;i<=vsend.length;i++) if(vsend.charAt(i)==" ") m=m+"_"; else m=m+vsend.charAt(i);
vsend=m;
ajaxFunction();
}
function getCodes(){
 username=r_id("username");
 vsend=username+"A"
 m="";for(i=0;i<=vsend.length;i++) if(vsend.charAt(i)==" ") m=m+"_"; else m=m+vsend.charAt(i);
 vsend=m;
 ajaxFunction();
}

function received(){
document.getElementById("inp").disabled=false;
s_id("receive",rcvd);
if(rcvd==""){s_id("msg","Σας έχει απαγορευθεί η είσοδος"); s_v("msg",'visible');return;}
ss=rcvd;
    s = ""
   for(i=0;i< ss.length;i++){
       if(ss.substr(i,1)=="="){
            if(ss.charCodeAt( i + 1)<58) {s = s + ss[i+1];i++}else{
            a = ss.charCodeAt( i + 1);if( a >= 65)  a = a - 7;
            a = a - 48;
            b = ss.charCodeAt( i + 2);if( b>= 65)  b = b - 7;
            b = b - 48;
            s = s + String.fromCharCode(a * 16 + b+720); i = i + 2;}
       }else{
            s = s + ss[i];
       }
    }
if (s.substr(0,1)=="B"){
m=s.search("/");document.getElementById("day").selectedIndex=parseInt(s.substr(3,m-2))-1;s=s.substr(m+1,s.length-m);
m=s.search("/");document.getElementById("month").selectedIndex=parseInt(s.substr(0,m))-1;s=s.substr(m+2,s.length-m-1);
m=s.search(" ");document.getElementById("year").selectedIndex=parseInt(s.substr(0,m))-2012;s=s.substr(m+1,s.length-m);
m=s.search(":");document.getElementById("hour").selectedIndex=parseInt(s.substr(0,m));s=s.substr(m+1,s.length-m);
m=s.search("#");document.getElementById("minutes").selectedIndex=parseInt(s.substr(0,m));s=s.substr(m+1,s.length-m);
m=s.search("#");s_id("firstname",s.substr(0,m));s=s.substr(m+1,s.length-m);
m=s.search("#");s_id("name",s.substr(0,m));s=s.substr(m+1,s.length-m);
m=s.search("#");s_id("phone",s.substr(0,m));s=s.substr(m+1,s.length-m);
m=s.search("#");s=s.substr(m+1,s.length-m);
m=s.search("#");s=s.substr(m+1,s.length-m);
m=s.search("#");s=s.substr(m+1,s.length-m);
m=s.search("#");s_id("addr1",s.substr(0,m));s=s.substr(m+1,s.length-m);
m=s.search("#");s=s.substr(m+1,s.length-m);
m=s.search("#");s_id("point1",s.substr(0,m));s=s.substr(m+1,s.length-m);
m=s.search("#");s=s.substr(m+1,s.length-m);
m=s.search("#");s=s.substr(m+1,s.length-m);
m=s.search("#");s=s.substr(m+1,s.length-m);
m=s.search("#");s=s.substr(m+1,s.length-m);
active=s;
document.getElementById("show").selectedIndex=-1;
if(changeactive==1) {active=1-active;sendrequest_3();firstin();return}
checkUpdate=1;trim();
return
}
if (s.substr(0,1)=="A"){
m=0;
for (m=1;m<s.length;m++) if(s.charAt(m)=='S') break;
ol=0;document.getElementById("show").options.length=0;
while(m<s.length){
for (k=m+1;k<s.length;k++) if(s.charAt(k)=='#') break;
sactive="Ενεργό";if(s.charAt(k+1)!="1")sactive="Ανενεργό"
document.getElementById("show").options[ol]=new Option(s.substr(m+2,k-m-2)+" <======> "+sactive,ol++);
m=k+2;
}
}
else{
if(s=="5"){s_id("msg","  Εχει αποσταλεί μήνυμα");s_v("msg",'visible');return;}
if(s=="4"){firstin();return;}
if(s=="3"){if(changeactive==0)s_v("success",'visible');changeactive=0;close_window();return;}
if(s=="1"){s_id("msg","    Λανθασμένος Κωδικός");s_v("msg",'visible');return;}
if(s=="0"){s_id("msg","Δεν έχετε εγγραφεί μέλος");s_v("msg",'visible');return;}
for(m=1;m<=s.length;m++)if(s.charAt(m)=="|") break;
if(m<s.length){
s_id("firstname",s.substr(1,m-1));
s=s.substr(m+1,s.length-m);
for(m=0;m<=s.length;m++)if(s.charAt(m)=="|") break;
s_id("name",s.substr(0,m));
s=s.substr(m+1,s.length-m);
for(m=0;m<=s.length;m++)if(s.charAt(m)=="|") break;
if(m<s.length){
s_id("phone",s.substr(0,m));
email=s.substr(m+1,s.length-m);
sendrequest_4();
}
}
}
home();
//check();trim();
}
function findb(){dt1=0;}
function newapp(){checkUpdate=0;active=1;check();trim();}
function activate(){changeactive=1;checkUpdate=1;sendrequest_5();}
function subm(){if(r_id("point1")=="")return;check1();sendrequest_3();}
function ret(){if(parent.process=="go"){setTimeout('ret1()',100);return;}clearTimeout(checkTime);submenable();firstin();}
function ajaxFunction(){var xmlHttp;try{xmlHttp=new XMLHttpRequest();}catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){alert("Your browser does not support AJAX!");return false;}}}
xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4){rcvd=xmlHttp.responseText;received();}}
rcvd="";
xmlHttp.open("POST","../php114/gen.php",true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send("send="+vsend+"1");
};
function ret1(){
parent.document.getElementById("wplightbox_closediv").click();
}

window['firstin']=firstin;
window['newapp']=newapp;
window['sendrequest_2']=sendrequest_2;
window['sendrequest_5']=sendrequest_5;
window['sendrequest_7']=sendrequest_7;
window['activate']=activate;
window['getLocation']=getLocation;
window['subm']=subm;
window['trim']=trim;
window['ret']=ret;
window['ggcode']=ggcode;
window['move']=move;
window['submenable']=submenable;
window['ajaxFunction']=ajaxFunction;
window['getCodes']=getCodes;
window['ret1']=ret1;
